package com.jwm.power.repository;

import com.jwm.power.model.entity.SysDics;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
public interface DicsRepository extends JpaRepository<SysDics, Integer>, JpaSpecificationExecutor<SysDics> {
    //  获取最大编码
    @Query(value = "select top 1 RIGHT(DicCode,2) from Sys_Dics where ParentCode=?1 order by DicCode DESC ", nativeQuery = true)
    String getMaxCode(String parentCode);
    //  获取最大序号
    @Query(value = "select top 1 sn from Sys_Dics where ParentCode=?1 order by sn DESC ", nativeQuery = true)
    Integer getMaxSn(String parentCode);
    //  验证同级名称是否重复
    List<SysDics> findByParentcodeAndDicname(@Param("parentcode") String parentcode , @Param("dicname") String dicname );

    SysDics findByDicid(@Param("dicid") Integer dicid);
    List<SysDics> findByParentcode(@Param("parentcode") String parentcode  );
}
